﻿using System;
using Microsoft.Xna.Framework;

namespace Firefly.Framework.Input
{
    public abstract class InputMap : IInputMap
    {
        public InputMap()
        {
            Enabled = true;
        }

        #region IInputMap Members

        public InputMapType InputMapType { get; protected set; }
        public string Action { get; protected set; }

        #endregion

        #region IUpdateable Members

        public event EventHandler EnabledChanged;
        public event EventHandler UpdateOrderChanged;

        private bool _enabled;
        private int _updateOrder;

        public bool Enabled
        {
            get { return _enabled; }
            set
            {
                if (value != _enabled)
                {
                    _enabled = value;
                    NotifyEnabledChanged();
                }
            }
        }
        public int UpdateOrder
        {
            get { return _updateOrder; }
            set
            {
                if (value != _updateOrder)
                {
                    _updateOrder = value;
                    NotifyUpdateOrderChanged();
                }
            }
        }

        protected void NotifyEnabledChanged()
        {
            EventHandler handler = EnabledChanged;

            if (handler != null)
            {
                handler(this, null);
            }
        }

        protected void NotifyUpdateOrderChanged()
        {
            EventHandler handler = UpdateOrderChanged;

            if (handler != null)
            {
                handler(this, null);
            }
        }

        public abstract void Update(GameTime gameTime);

        #endregion
    }
}
